<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="user_id" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="user_name" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">邮箱</label>
                            <div class="layui-input-inline">
                                <input type="text" name="mail" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <!-- <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button> -->
                <!-- <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button> -->
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <!-- <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a> -->
            <!-- <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a> -->
        </script>

    </div>
</div>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    function getCookie(name) {
        var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
        return r ? r[1] : undefined;
    }

    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        let data = {
            "user_id": "",
            "user_name": "",
            "mail": ""
        }
        table.render({
            elem: '#currentTableId',
            method: 'post',
            headers: {
                'X-CSRFToken': getCookie('csrf_token')
            },
            url: '/api/v1.0/user_list',
            // url: '/api/v1.0/user_list',
            contentType: 'application/json',
            request: {
                pageName: 'curr', //页码的参数名称，默认：page
                limitName: 'nums' //每页数据量的参数名，默认：limit
            },
            where: {
                // searchParams: JSON.stringify(data)
                searchParams: data
            },
            cols: [
                [{
                    type: "checkbox",
                    width: 50
                },
                    {
                        field: 'user_id',
                        width: 150,
                        title: 'ID',
                        sort: true
                    },
                    {
                        field: 'user_name',
                        width: 150,
                        title: '用户名'
                    },
                    {
                        field: 'mail',
                        width: 250,
                        title: '邮箱',
                        sort: true
                    },
                    {
                        field: 'is_vip',
                        width: 80,
                        title: 'vip',
                        templet: function (date) {
                            return date.is_vip == 1 ? "是" : "否"
                        }
                    },
                    {
                        title: '操作',
                        minWidth: 60,
                        toolbar: '#currentTableBar',
                        align: "center"
                    }
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            groups: 3,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            // var result = JSON.stringify(data.field);
            var result = data.field;
            // layer.alert(result, {
            // 	title: '最终的搜索信息'
            // });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                },
                where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        // table.on('toolbar(currentTableFilter)', function(obj) {
        // 	if (obj.event === 'delete') { // 监听删除操作
        // 		var checkStatus = table.checkStatus('currentTableId'),
        // 			data = checkStatus.data;
        // 		layer.alert(JSON.stringify(data));
        // 	}
        // });

    });
</script>

</body>
</html>
